package main

import (
	"fmt"
	"sort"
)

func main() {
	names := MyStringList{"3", "1", "2"}
	sort.Sort(names)
	for _, v := range names {
		fmt.Printf("%s\n", v)
	}
}

type MyStringList []string

type Interface interface {
	Len() int
	Less(i, j int) bool
	Swap(i, j int)
}

//sort.Sort定义了Len()未实现接口方法，需要手动去实现
func (m MyStringList) Len() int {
	fmt.Println("实现Len")
	return len(m)
}

func (m MyStringList) Less(i, j int) bool {
	fmt.Println("实现Less")
	return m[i] < m[j]
}

func (m MyStringList) Swap(i, j int) {
	fmt.Println("实现Swap")
	m[i], m[j] = m[j], m[i]
}
